/**
 * elancom Corporation copy right 2012 - 2015  
 *   
 * $Header$
 * $Id$
 * $Author$
 * $Date$
 * $Revision$
 */
package com.elancom.framework.dao;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.elancom.framework.commons.limit.Limit;
import com.elancom.framework.commons.limit.LimitImpl;

/**
 * @author elancom
 * @date 2012-8-22
 */
public class Result implements Serializable {
	private static final long serialVersionUID = -4444485682221815321L;

	protected int curPage = 0;

	protected int firstResult = -1;

	private List<?> dataSet = null;

	protected int totalResults = 0;

	private Limit limit = null;

	public Limit getLimit() {
		return this.limit != null ? this.limit : new LimitImpl();
	}

	void setLimit(Limit limit) {
		this.limit = limit;
	}

	@SuppressWarnings("unchecked")
	public <M> List<M> getResult() {
		return (List<M>) (dataSet == null ? new ArrayList<M>(0) : dataSet);
	}

	public int getResultSize() {
		return this.dataSet == null ? 0 : this.dataSet.size();
	}

	@SuppressWarnings("unchecked")
	public <M> M getFirstResult() {
		return (M) (this.dataSet == null ? null : this.dataSet.get(0));
	}

	public boolean isEmpty() {
		return getResultSize() == 0;
	}

	<M> void setResult(List<M> list) {
		this.dataSet = list;
	}

	/**
	 * @return the curPage
	 */
	public int getCurPage() {
		return curPage;
	}

	/**
	 * @param curPage
	 *            the curPage to set
	 */
	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}
}
